package com.zhicheng.mapper;

import com.zhicheng.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper{
    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    /**
     * 注册用户
     * @param username
     * @param password
     */
    @Insert("insert into user(username,password,nickname,create_time,update_time) values (#{username},#{password},#{username},NOW(),NOW())")
    void add(String username, String password);

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getUserById(Long id);

    void update(User user);

    @Update("update user set password = #{password},update_time = now()")
    void updatePwd(String password);

    @Update("update user set user_pic = #{avatarUrl},update_time=now() where id = #{id}")
    void updateAvatar(String avatarUrl, Long id);

    @Select("select * from user")
    List<User> list();

}
